

void ReconnectionManager::reconnect() {
	if (isReconnectionAllowed()) {
		reconnectionThread = new ReconnectionThread(this);
		reconnectionThread->setName("Smack Reconnection Manager");
		reconnectionThread->setDaemon(true);
		reconnectionThread->start();
	}
}


bool isReconnectionAllowed() {
        return !done && !connection->isConnected()
                && connection->getConfiguration()->isReconnectionAllowed()
                && connection->packetReader != NULL;
}


void notifyReconnectionFailed(Exception exception) {
	std::list<ConnectionListener*> listenersCopy;
	if (isReconnectionAllowed()) {
		std::set<ConnectionListener*> & connectionListeners = connection->getPacketReader()->getConnectionLinsteners();
		std::for_each(connectionListeners.begin(), connectionListeners.end(), mem_fun(&ConnectionListener::reconnectionFailed));
	}
}


void notifyAttemptToReconnectIn(int seconds) {
	std::list<ConnectionListener*> listenersCopy;
	if (isReconnectionAllowed()) {
		std::set<ConnectionListener*> & connectionListeners = connection->getPacketReader()->getConnectionLinsteners();
		std::for_each(connectionListeners.begin(), connectionListeners.end(), std::bind2nd(std::mem_fun(&ConnectionListener::reconnectingIn), seconds));
	}
}



